home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
timedat.exe
/
DEMO.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-09
|
10KB
|
313 lines
/*
Copyright 1992 - John K. Humkey
*/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <dos.h>
#include "timespan.h"
#include "timpoint.h"
void astro_to_date(int *year, int *month, int *day, long *ast);
void date_to_astro(int *year, int *month, int *day, long *ast);
void time_to_astro(int *hour, int *mins, int *sec, int *millisec, long *ast);
void astro_to_time(int *hour, int *mins, int *sec, int *millisec, long *ast);
void span_demo();
void point_demo();
int __european;
main()
{
__european = 0;
span_demo();
point_demo();
}
void span_demo()
{
timespan comboone(100L,0,29,29);
timespan combotwo(100L,0,29,29);
timespan combothree(200L,0,0,0);
timespan combofour(100L,0,29,30);
timespan combototal;
clrscr();
printf("\nTime Span Demo\n\n");
printf("ts = ts + ts\n");
combototal = comboone + combotwo;
comboone.print();
combotwo.print();
combototal.print();
printf("\n"); getch();
printf("ts = ta - tb (a<b type 1)\n");
combototal = comboone - combothree;
comboone.print();
combothree.print();
combototal.print();
printf("\n"); getch();
printf("ts = ta - tb (a<b type 2)\n");
combototal = comboone - combofour;
comboone.print();
combofour.print();
combototal.print();
printf("\n"); getch();
printf("ts = ta - tb (a==b)\n");
combototal = comboone - combotwo;
comboone.print();
combotwo.print();
combototal.print();
printf("\n"); getch();
printf("ts = ta - tb (a>b type 1)\n");
combototal = combothree - comboone;
combothree.print();
comboone.print();
combototal.print();
printf("\n"); getch();
printf("ts = ta - tb (a>b type 2)\n");
combototal = combofour - comboone;
combofour.print();
comboone.print();
combototal.print();
printf("\n"); getch();
printf("ts = ts * 2\n");
combototal = combothree * 2;
combothree.print();
combototal.print();
printf("\n"); getch();
printf("ts = ts / 2\n");
combototal = combothree / 2;
combothree.print();
combototal.print();
printf("\n"); getch();
printf("ta < tb\n");
printf("should be 1 is %d\n",comboone < combothree);
printf("should be 1 is %d\n",comboone < combofour);
printf("should be 0 is %d\n",comboone < combotwo);
printf("should be 0 is %d\n",combothree < comboone);
printf("should be 0 is %d\n",combofour < comboone);
printf("\n"); getch();
printf("ta > tb\n");
printf("should be 0 is %d\n",comboone > combothree);
printf("should be 0 is %d\n",comboone > combofour);
printf("should be 0 is %d\n",comboone > combotwo);
printf("should be 1 is %d\n",combothree > comboone);
printf("should be 1 is %d\n",combofour > comboone);
printf("\n"); getch();
printf("ta == tb\n");
printf("should be 0 is %d\n",comboone == combothree);
printf("should be 0 is %d\n",comboone == combofour);
printf("should be 1 is %d\n",comboone == combotwo);
printf("should be 0 is %d\n",combothree == comboone);
printf("should be 0 is %d\n",combofour == comboone);
printf("\n"); getch();
printf("ta != tb\n");
printf("should be 1 is %d\n",comboone != combothree);
printf("should be 1 is %d\n",comboone != combofour);
printf("should be 0 is %d\n",comboone != combotwo);
printf("should be 1 is %d\n",combothree != comboone);
printf("should be 1 is %d\n",combofour != comboone);
printf("\n"); getch();
printf("ta <= tb\n");
printf("should be 1 is %d\n",comboone <= combothree);
printf("should be 1 is %d\n",comboone <= combofour);
printf("should be 1 is %d\n",comboone <= combotwo);
printf("should be 0 is %d\n",combothree <= comboone);
printf("should be 0 is %d\n",combofour <= comboone);
printf("\n"); getch();
printf("ta >= tb\n");
printf("should be 0 is %d\n",comboone >= combothree);
printf("should be 0 is %d\n",comboone >= combofour);
printf("should be 1 is %d\n",comboone >= combotwo);
printf("should be 1 is %d\n",combothree >= comboone);
printf("should be 1 is %d\n",combofour >= comboone);
printf("\n"); getch();
printf("ts += ts\n");
combototal = comboone;
combototal.print();
combototal += combotwo;
combotwo.print();
combototal.print();
printf("\n"); getch();
printf("ts -= ts\n");
combototal = combothree;
combototal.print();
combototal -= combotwo;
combotwo.print();
combototal.print();
printf("\n"); getch();
}
void point_demo()
{
char str[80];
timepoint comboone(1962,9,2,2,29,29);
timespan combotwo(0,0,30,30);
timepoint combothree(0,0,0,2,10,10);
timepoint combototal;
clrscr();
printf("\nTime Point Demo\n\n");
combototal = comboone + combotwo;
comboone.print();
combotwo.print();
combototal.print();
printf("\nTime Point String Demo\n\n");
printf("American format\n");
printf("mdy2w %s\n",comboone.mdy2w(str));
printf("mdy4w %s\n",comboone.mdy4w(str));
printf("mdy2 %s\n",comboone.mdy2(str));
printf("mdy4 %s\n",comboone.mdy4(str));
printf("y2md %s\n",comboone.y2md(str));
printf("y4md %s\n",comboone.y4md(str));
printf("\nEuropean format\n");
__european = 1;
printf("mdy2w %s\n",comboone.mdy2w(str));
printf("mdy4w %s\n",comboone.mdy4w(str));
printf("mdy2 %s\n",comboone.mdy2(str));
printf("mdy4 %s\n",comboone.mdy4(str));
printf("y2md %s\n",comboone.y2md(str));
printf("y4md %s\n",comboone.y4md(str));
getch();
}
/* # # #### ##### # #### ###### */
/* ## # # # # # # # # */
/* # # # # # # # # ##### */
/* # # # # # # # # # */
/* # ## # # # # # # # */
/* # # #### # # #### ###### */
/* */
/* The following routines are used by the timepoint */
/* and timespan classes, and will need to be placed */
/* in your normal user libraries (or included in */
/* source form in your code.) */
/* The following routines... */
/* */
/* astro_to_date */
/* date_to_astro */
/* astro_to_time */
/* time_to_astro */
/* */
/* were taken from an article in "68' Micro Journal"*/
/* from Volume VIII Issue II * February 1986. */
/* */
/* To the best of my knowledge the magazine is out */
/* of business, which is a shame because they pub- */
/* lished some interesting source code. */
/* */
/* The article was under "C" User Notes and was by */
/* Edgar M. (Bud) Pass, Ph.D. */
/* Mr. Pass adapted the routines from ... */
/* "Communications of the ACM * Oct 68 p657, Oct 70 */
/* p621, Oct 72 p918. */
/* */
/* Several other routines are included in the */
/* original article (to calculate the day of the */
/* year, day of the week) but are not needed for the*/
/* timepoint and timespan classes. */
/* */
/* I don't pretend to understand the underlying */
/* theory of how the routines work, I just know that*/
/* used in combination with the timepoint and */
/* timespan classes they can accurately represent */
/* any point from about 4000 years ago to any point */
/* in the future (with down to the millisecond */
/*